package main

import "fmt"

/**

Given a non-empty array of integers, every element appears twice except for one. Find that single one.

Note:

Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?

Example 1:

Input: [2,2,1]
Output: 1
Example 2:

Input: [4,1,2,1,2]
Output: 4

单身数

要点:
^异或操作 A^A=0
12124 遍历异或 1^1^2^2^4 = 0^0^4=4

其他知识
A^B=C C^B=A 是可逆的
A^0=A
*/

func singleNumber(nums []int) int {
	if len(nums) == 0 {
		return 0
	}

	res := nums[0]
	for i := 1; i < len(nums); i++ {
		res = res ^ nums[i]
	}
	return res
}

func main() {
	fmt.Println(1 ^ 1 ^ 10)
}
